package com.qf.fanwang.service.impl;

import com.qf.fanwang.dao.GoodDao;
import com.qf.fanwang.dao.GoodsDao;
import com.qf.fanwang.pojo.Good;
import com.qf.fanwang.pojo.Goods;
import com.qf.fanwang.service.GoodService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

public class GoodServiceImpl implements GoodService {
    private GoodDao gd;

    @Override
    public List<Good> selectAll() {
        try {
            SqlSession sqlSession = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis.xml")).openSession(true);
            gd=sqlSession.getMapper(GoodDao.class);
            return gd.selectAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;

    }

    @Override
    public List<Good> selectALLById(int id) {
        try {
            SqlSession sqlSession = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis.xml")).openSession(true);
            gd=sqlSession.getMapper(GoodDao.class);
            return gd.selectALLById(id);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
